package com.zhangyu.shadow.repair.delegate.irregular;

import android.content.Context;
import android.support.graphics.drawable.VectorDrawableCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhangyu.shadow.repair.R;
import com.zhangyu.shadow.repair.delegate.bean.VehicleBean;

import java.util.List;

/**
 * Created by 张宇 on 2017/3/15.
 */

public class IrregularBusListAdapter extends BaseQuickAdapter<VehicleBean, BaseViewHolder> {
    private VectorDrawableCompat mDrawableCompatReady;
    private VectorDrawableCompat mDrawableCompatDoing;
    private VectorDrawableCompat mDrawableCompatComplete;


    public IrregularBusListAdapter(Context context, int layoutResId, List<VehicleBean> data) {
        super(layoutResId, data);
        mDrawableCompatReady = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_on_hand, context.getTheme());
        mDrawableCompatDoing = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_maintenance, context.getTheme());
        mDrawableCompatComplete = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_complete, context.getTheme());
    }

    @Override
    protected void convert(BaseViewHolder helper, VehicleBean item) {
        helper.addOnClickListener(R.id.card_view);
        helper.setText(R.id.tv_bus_number, item.getVehicleCode());
        helper.setText(R.id.tv_maintain_type, item.getTypeName());
        int code = item.getOperateType();
        helper.setVisible(R.id.iv_ready, false);
        helper.setVisible(R.id.tv_stay_day, false);
        switch (code) {
            case 0://待交车
                helper.setVisible(R.id.tv_stay_day, false);
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatReady);
                helper.setText(R.id.tv_bus_plan_time, item.getVmType() == 2 ? "" +
                        "报修时间:" + item.getInFactoryTime() :
                        "计划保养时间:" + item.getPlanStartTime());
                break;
            case 1:
                //保养
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatDoing);
                helper.setVisible(R.id.tv_stay_day, true);
                helper.setText(R.id.tv_bus_plan_time, "计划保养时间:" +
                        item.getPlanStartTime());
            case 2:
                //小修
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatDoing);
                helper.setVisible(R.id.tv_stay_day, true);
                helper.setText(R.id.tv_bus_plan_time, "报修时间:" +
                        item.getInFactoryTime());
                break;
            default:
                helper.setVisible(R.id.tv_stay_day, false);
                helper.setImageDrawable(R.id.img_bus, mDrawableCompatComplete);
                break;
        }
        helper.setText(R.id.tv_stay_day, "已停留" + "("
                + String.valueOf(item.getStayDays()) + ")天");
        helper.setText(R.id.tv_bus_line, item.getRouteName());
        String startTime = item.getActualStartTime();
        if (startTime == null || startTime.isEmpty() || "null".equals(startTime)) {
            startTime = "未开始";
        }
        helper.setText(R.id.tv_bus_actual_start_time, "开始:" + startTime);

        String endTime = item.getActualEndTime();
        if (endTime == null || endTime.isEmpty() || "null".equals(endTime)) {
            endTime = "未完成";
        }
        helper.setText(R.id.tv_bus_actual_end_time, "完成:" + endTime);

    }

}
